package Main;

import java.awt.event.KeyEvent;
import java.awt.image.BufferedImage;
import java.io.IOException;

import javax.imageio.ImageIO;
import javax.media.opengl.GL;
import javax.swing.JOptionPane;

import com.sun.opengl.util.texture.Texture;
import com.sun.opengl.util.texture.TextureIO;

public class Item_Box extends MyCube {
	public Boolean m_Test_Select=false;
	public Boolean m_Test_Choose=false;
	public Boolean m_Test_Unlock=false;
	public Item_Box()
	{
		m_Test_Select=false;
		m_Test_Choose=false;
		m_Test_Unlock=false;
		
	}
	public void LoadImage(String _path)
	{
		if(m_Test_Unlock==true)
			m_Cube_Tex=LoadTexture(_path);
		else
			m_Cube_Tex=LoadTexture("LevelBox0.png");
		m_Cube_Tex.enable();
	}
	public void Init()
	{
		LoadImage(DefineCons.LEVEL1);
		initVertexNomal();
	}
	
	public void DisPlay(GL gl)
	{
		update();
		gl.glPushMatrix();
		gl.glTranslated(m_Cube_X, m_Cube_Y, m_Cube_Z);
		gl.glRotatef(m_Cube_RoX, 0,1, 0);
		gl.glRotatef(m_Cube_RoY, 1,0, 0);
		gl.glRotatef(m_Cube_RoZ, 0,0, 1);
		DrawCube(m_Cube_Tex, gl);
		gl.glPopMatrix();
		
	}
	public void update()
	{
		if(m_Test_Select==true)
		{
			m_Cube_RoZ+=1;
		}
		else
		{
			if(m_Cube_RoZ%90!=0)
			{
				m_Cube_RoZ+=1;
			}
		}
	}
	public void keyPressed(KeyEvent arg0) {
		// TODO Auto-generated method stub
    	
	}
	
	
	
	public Texture LoadTexture(String _path){
		Texture _result;
		BufferedImage image;
		try{
			image = ImageIO.read(this.getClass().getResource(_path));
			_result = TextureIO.newTexture(image,false);
		}catch(IllegalArgumentException e){
			JOptionPane.showMessageDialog(null, "Can not load file \"" + _path + "\". The application will be exit !"+e.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
			//System.exit(0);
			return null;
		}catch(IOException e){
			e.printStackTrace();
			return null;
		}
		return _result;
		
	}
	public void initVertexNomal()
	{
		
		// Front Face
		m_ArrayPointVertex[0] = new Point3D( 0.5f, 0.5f, 1.0f);
        m_ArrayPointVertex[1] = new Point3D(-0.5f, 0.5f, 1.0f);
        m_ArrayPointVertex[2] = new Point3D(-0.5f,-0.5f, 1.0f);
        m_ArrayPointVertex[3] = new Point3D( 0.5f,-0.5f, 1.0f);
        // Back Face
        m_ArrayPointVertex[4] = new Point3D( 0.5f, 0.5f, 0.0f);
        m_ArrayPointVertex[5] = new Point3D( 0.5f,-0.5f, 0.0f);
        m_ArrayPointVertex[6] = new Point3D(-0.5f,-0.5f, 0.0f);
        m_ArrayPointVertex[7] = new Point3D(-0.5f, 0.5f, 0.0f);
        // Top Face
        m_ArrayPointVertex[8] = new Point3D(-0.5f,-0.5f, 1.0f);
        m_ArrayPointVertex[9] = new Point3D(-0.5f,-0.5f, 0.0f);
        m_ArrayPointVertex[10]= new Point3D( 0.5f,-0.5f, 0.0f);
        m_ArrayPointVertex[11]= new Point3D( 0.5f,-0.5f, 1.0f);
        // Bottom Face
        m_ArrayPointVertex[12]= new Point3D( 0.5f, 0.5f, 1.0f);
        m_ArrayPointVertex[13]= new Point3D( 0.5f, 0.5f, 0.0f);
        m_ArrayPointVertex[14]= new Point3D(-0.5f, 0.5f, 0.0f);
        m_ArrayPointVertex[15]= new Point3D(-0.5f, 0.5f, 1.0f);
        // Right face
        m_ArrayPointVertex[16]= new Point3D(-0.5f, 0.5f, 1.0f);
        m_ArrayPointVertex[17]= new Point3D(-0.5f, 0.5f, 0.0f);
        m_ArrayPointVertex[18]= new Point3D(-0.5f,-0.5f, 0.0f);
        m_ArrayPointVertex[19]= new Point3D(-0.5f,-0.5f, 1.0f);
        // Left Face
        m_ArrayPointVertex[20]= new Point3D( 0.5f, 0.5f, 0.0f);
        m_ArrayPointVertex[21]= new Point3D( 0.5f, 0.5f, 1.0f);
        m_ArrayPointVertex[22]= new Point3D( 0.5f,-0.5f, 1.0f);
        m_ArrayPointVertex[23]= new Point3D( 0.5f,-0.5f, 0.0f);
        
        
	}
	
}
